package org.phalanx.client.net;

import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.ChatManagerListener;
import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.packet.Message;
import org.phalanx.messenging.management.MessageManager;

public class PhalanxConnectionListener implements ChatManagerListener, MessageListener{
	private String serverNode;
	private MessageManager msgMgr;
	private boolean messageOk;
	
	public PhalanxConnectionListener(String nodeName, MessageManager messageManager) {
		this.serverNode = nodeName.toLowerCase();
		msgMgr = messageManager;
	}
	
	public void chatCreated(Chat arg0, boolean arg1) {
		String chatFrom = arg0.getParticipant().toLowerCase();
		if (chatFrom.equals(serverNode)) {
			messageOk = true;
			arg0.addMessageListener(this);
		}
		else {
			messageOk = false;
		}
	}

	public void processMessage(Chat arg0, Message arg1) {
		if (messageOk) {
			//msgMgr.receiveMessage(arg1);
		}
	}
	
	
}
